package com.zm.demo.core.nio;

import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.DatagramChannel;

import static java.lang.System.out;

/**
 * @author zoum
 * @create 2019/9/16 17:26
 */
public class DatagramChannelConnectT {


    public static void main(String[] args)throws Exception {

        DatagramChannel channel = DatagramChannel.open();
//        channel.socket().bind(new InetSocketAddress(9911));
        channel.connect(new InetSocketAddress("localhost",9912));

        ByteBuffer buf = ByteBuffer.allocate(48);
        buf.put("first".getBytes());
        buf.flip();
        int r = channel.read(buf);
        out.println("read：" + r);

        int w = channel.write(buf);
        out.println("write：" + w);
    }
}
